<?php
    session_start();
    require_once('userlevel.php'); //Require/include the permissions file
    require_once('template.php'); //Require/include the functions file
    require_once('db.php'); //Require/include the file with the database connection information
     
    if (!$_SESSION['user_loggedin']) {
        die ("Not logged in... <script>document.location.href='login.php'</script>");
    } elseif (!($_SESSION['userlevel'] >= $userlevel['main'])) {
        die (errorpage ("Your user level is not high enough to use this feature!", 'Display Bin'));
    } else {
         
        //Connect to DB using db.php
        $db = new my_db;
         
        $id = mysql_escape_string($_GET['id']);
        $db->query("SELECT * FROM binarycontent WHERE dataid = '$id'");
        if ($db->nf() > 0) {
            $db->next_record();
            $filetype = $db->f('filetype');
            $content = $db->f('content');
            header("Content-type: $filetype");
            echo $content;
        } else {
            echo "Error: content not found";
        }
    }
?>